package com.tms.operation.mapper;

import java.util.List;
import com.tms.operation.domain.TmsDraw;
import org.apache.ibatis.annotations.Select;

/**
 * 到站Mapper接口
 *
 * @author ruoyi
 * @date 2024-10-28
 */
public interface TmsDrawMapper
{
    /**
     * 查询到站
     *
     * @param id 到站主键
     * @return 到站
     */
    public TmsDraw selectTmsDrawById(Long id);

    /**
     * 查询到站列表
     *
     * @param tmsDraw 到站
     * @return 到站集合
     */
    public List<TmsDraw> selectTmsDrawList(TmsDraw tmsDraw);

    /**
     * 新增到站
     *
     * @param tmsDraw 到站
     * @return 结果
     */
    public int insertTmsDraw(TmsDraw tmsDraw);

    /**
     * 修改到站
     *
     * @param tmsDraw 到站
     * @return 结果
     */
    public int updateTmsDraw(TmsDraw tmsDraw);

    /**
     * 删除到站
     *
     * @param id 到站主键
     * @return 结果
     */
    public int deleteTmsDrawById(Long id);

    /**
     * 批量删除到站
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTmsDrawByIds(Long[] ids);

    @Select("SELECT DISTINCT\n" +
            "  d2.pickup_order pid,\n" +
            "  d2.driver,\n" +
            "  d2.phone_number pho,\n" +
            "  d1.num,\n" +
            "\td3.num2,\n" +
            "\t(d1.num-d3.num2) num3\n" +
            "\t\n" +
            "FROM \n" +
            "  (SELECT driver, COUNT(driver) AS num \n" +
            "   FROM tms_draw \n" +
            "   WHERE is_arrived = 1 \n" +
            "   GROUP BY driver) d1\n" +
            "JOIN \n" +
            "  (SELECT pickup_order, driver, phone_number \n" +
            "   FROM tms_draw) d2\n" +
            "ON \n" +
            "  d1.driver = d2.driver\n" +
            "JOIN\n" +
            "(select driver,count(*) num2  from tms_draw where actual_arrival_time <= planned_arrival_time and is_arrived = 1 GROUP BY driver) d3 \n" +
            "ON\n" +
            " d1.driver = d3.driver")
    List<TmsDraw> countdraw();

//    @Select("select * from tms_draw where actual_arrival_time > planned_arrival_time")
    List<TmsDraw> exceptDraw();
}
